package ru.fadeev.crammer.phrasedb;

import java.io.File;
import java.io.FileFilter;


public class TextFileFilter implements FileFilter {
	public String getExtension(File file) {
		String extension = null;
        String s = file.getName();
        int i = s.lastIndexOf('.');

        if (i > 0 &&  i < s.length() - 1) {
        	extension = s.substring(i+1).toLowerCase();
        }
        return extension;
	}
	
	public boolean accept(File file) {
		if (file.isDirectory()) {
			return true;
		}
	
		String extension = getExtension(file);

		if (extension != null) {
			if (extension.equals("txt")) {
				return true;
			} else {
				return false;
			}
		}
		return false;
    }
}
